package com.icesoft.system.controller;

import com.icesoft.framework.core.controller.BaseController;
import com.icesoft.framework.core.vo.JsonResult;
import com.icesoft.system.entity.User;
import com.icesoft.system.service.impl.CompanyServiceImpl;
import com.icesoft.system.service.impl.UserServiceImpl;
import com.icesoft.system.util.SecurityUtils;
import com.icesoft.system.vo.CompanyVO;
import com.icesoft.system.vo.MenuVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/user-info")
public class UserInfoController extends BaseController {

	private final CompanyServiceImpl companyService;

	private final UserServiceImpl userService;

	@GetMapping("company")
	public JsonResult<?> company() {
		User user = SecurityUtils.getCurrentUser();
		CompanyVO companyVO = companyService.getViewObject(user.getCompanyId(), CompanyVO.class);
		return JsonResult.OK(companyVO);
	}

	@GetMapping("menu")
	public JsonResult<?> menu() {
		User user = SecurityUtils.getCurrentUser();
		List<MenuVO> list = userService.getMenu(user.getId());
		return JsonResult.OK(list);
	}
}
